<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Buffer Node.js v5.6.0 Manual &amp; Documentation</title>

  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="buffer.html">
</head>
<body class="alt apidoc" id="api-section-buffer">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div class="no-scrollbar">
        <div id="intro" class="interior">
          <a href="./" title="Go back to the home page">
            Node.js (1)
          </a>
        </div>
        <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Synopsis</a></li>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer active" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C/C++ Addons</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https" href="https.html">HTTPS</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>

      </div>
    </div>

    <div id="column1" data-id="buffer" class="interior">
      <header>
        <h1>Node.js v5.6.0 Documentation</h1>
        <div id="gtoc">
          <p>
            <a href="index.html" name="toc">Index</a> |
            <a href="all.html">View on single page</a> |
            <a href="buffer.json">View as JSON</a>
          </p>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><a href="buffer.html#buffer_buffer">Buffer</a><ul>
<li><a href="buffer.html#buffer_buffers_and_character_encodings">Buffers and Character Encodings</a></li>
<li><a href="buffer.html#buffer_buffers_and_typedarray">Buffers and TypedArray</a></li>
<li><a href="buffer.html#buffer_buffers_and_es6_iteration">Buffers and ES6 iteration</a></li>
<li><a href="buffer.html#buffer_class_buffer">Class: Buffer</a><ul>
<li><a href="buffer.html#buffer_new_buffer_array">new Buffer(array)</a></li>
<li><a href="buffer.html#buffer_new_buffer_buffer">new Buffer(buffer)</a></li>
<li><a href="buffer.html#buffer_new_buffer_arraybuffer">new Buffer(arrayBuffer)</a></li>
<li><a href="buffer.html#buffer_new_buffer_size">new Buffer(size)</a></li>
<li><a href="buffer.html#buffer_new_buffer_str_encoding">new Buffer(str[, encoding])</a></li>
<li><a href="buffer.html#buffer_class_method_buffer_bytelength_string_encoding">Class Method: Buffer.byteLength(string[, encoding])</a></li>
<li><a href="buffer.html#buffer_class_method_buffer_compare_buf1_buf2">Class Method: Buffer.compare(buf1, buf2)</a></li>
<li><a href="buffer.html#buffer_class_method_buffer_concat_list_totallength">Class Method: Buffer.concat(list[, totalLength])</a></li>
<li><a href="buffer.html#buffer_class_method_buffer_isbuffer_obj">Class Method: Buffer.isBuffer(obj)</a></li>
<li><a href="buffer.html#buffer_class_method_buffer_isencoding_encoding">Class Method: Buffer.isEncoding(encoding)</a></li>
<li><a href="buffer.html#buffer_buf_index">buf[index]</a></li>
<li><a href="buffer.html#buffer_buf_compare_otherbuffer">buf.compare(otherBuffer)</a></li>
<li><a href="buffer.html#buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend">buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])</a></li>
<li><a href="buffer.html#buffer_buf_entries">buf.entries()</a></li>
<li><a href="buffer.html#buffer_buf_equals_otherbuffer">buf.equals(otherBuffer)</a></li>
<li><a href="buffer.html#buffer_buf_fill_value_offset_end">buf.fill(value[, offset[, end]])</a></li>
<li><a href="buffer.html#buffer_buf_indexof_value_byteoffset_encoding">buf.indexOf(value[, byteOffset][, encoding])</a></li>
<li><a href="buffer.html#buffer_buf_includes_value_byteoffset_encoding">buf.includes(value[, byteOffset][, encoding])</a></li>
<li><a href="buffer.html#buffer_buf_keys">buf.keys()</a></li>
<li><a href="buffer.html#buffer_buf_length">buf.length</a></li>
<li><a href="buffer.html#buffer_buf_readdoublebe_offset_noassert">buf.readDoubleBE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readdoublele_offset_noassert">buf.readDoubleLE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readfloatbe_offset_noassert">buf.readFloatBE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readfloatle_offset_noassert">buf.readFloatLE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readint8_offset_noassert">buf.readInt8(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readint16be_offset_noassert">buf.readInt16BE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readint16le_offset_noassert">buf.readInt16LE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readint32be_offset_noassert">buf.readInt32BE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readint32le_offset_noassert">buf.readInt32LE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readintbe_offset_bytelength_noassert">buf.readIntBE(offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readintle_offset_bytelength_noassert">buf.readIntLE(offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuint8_offset_noassert">buf.readUInt8(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuint16be_offset_noassert">buf.readUInt16BE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuint16le_offset_noassert">buf.readUInt16LE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuint32be_offset_noassert">buf.readUInt32BE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuint32le_offset_noassert">buf.readUInt32LE(offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuintbe_offset_bytelength_noassert">buf.readUIntBE(offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_readuintle_offset_bytelength_noassert">buf.readUIntLE(offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_slice_start_end">buf.slice([start[, end]])</a></li>
<li><a href="buffer.html#buffer_buf_tostring_encoding_start_end">buf.toString([encoding[, start[, end]]])</a></li>
<li><a href="buffer.html#buffer_buf_tojson">buf.toJSON()</a></li>
<li><a href="buffer.html#buffer_buf_values">buf.values()</a></li>
<li><a href="buffer.html#buffer_buf_write_string_offset_length_encoding">buf.write(string[, offset[, length]][, encoding])</a></li>
<li><a href="buffer.html#buffer_buf_writedoublebe_value_offset_noassert">buf.writeDoubleBE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writedoublele_value_offset_noassert">buf.writeDoubleLE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writefloatbe_value_offset_noassert">buf.writeFloatBE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writefloatle_value_offset_noassert">buf.writeFloatLE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeint8_value_offset_noassert">buf.writeInt8(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeint16be_value_offset_noassert">buf.writeInt16BE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeint16le_value_offset_noassert">buf.writeInt16LE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeint32be_value_offset_noassert">buf.writeInt32BE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeint32le_value_offset_noassert">buf.writeInt32LE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeintbe_value_offset_bytelength_noassert">buf.writeIntBE(value, offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeintle_value_offset_bytelength_noassert">buf.writeIntLE(value, offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuint8_value_offset_noassert">buf.writeUInt8(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuint16be_value_offset_noassert">buf.writeUInt16BE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuint16le_value_offset_noassert">buf.writeUInt16LE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuint32be_value_offset_noassert">buf.writeUInt32BE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuint32le_value_offset_noassert">buf.writeUInt32LE(value, offset[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuintbe_value_offset_bytelength_noassert">buf.writeUIntBE(value, offset, byteLength[, noAssert])</a></li>
<li><a href="buffer.html#buffer_buf_writeuintle_value_offset_bytelength_noassert">buf.writeUIntLE(value, offset, byteLength[, noAssert])</a></li>
</ul>
</li>
<li><a href="buffer.html#buffer_buffer_inspect_max_bytes">buffer.INSPECT_MAX_BYTES</a></li>
<li><a href="buffer.html#buffer_class_slowbuffer">Class: SlowBuffer</a></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>Buffer<span><a class="mark" href="buffer.html#buffer_buffer" id="buffer_buffer">#</a></span></h1>
<pre class="api_stability_2">Stability: 2 - Stable</pre><p>Prior to the introduction of <code>TypedArray</code> in ECMAScript 2015 (ES6), the
JavaScript language had no mechanism for reading or manipulating streams
of binary data. The <code>Buffer</code> class was introduced as part of the Node.js
API to make it possible to interact with octet streams in the context of things
like TCP streams and file system operations.

</p>
<p>Now that <code>TypedArray</code> has been added in ES6, the <code>Buffer</code> class implements the
<code>Uint8Array</code> API in a manner that is more optimized and suitable for Node.js&#39;
use cases.

</p>
<p>Instances of the <code>Buffer</code> class are similar to arrays of integers but
correspond to fixed-sized, raw memory allocations outside the V8 heap.
The size of the <code>Buffer</code> is established when it is created and cannot be
resized.

</p>
<p>The <code>Buffer</code> class is a global within Node.js, making it unlikely that one
would need to ever use <code>require(&#39;buffer&#39;)</code>.

</p>
<pre><code class="js">const buf1 = new Buffer(10);
  // creates a buffer of length 10

const buf2 = new Buffer([1,2,3]);
  // creates a buffer containing [01, 02, 03]

const buf3 = new Buffer(&#39;test&#39;);
  // creates a buffer containing ASCII bytes [74, 65, 73, 74]

const buf4 = new Buffer(&#39;tést&#39;, &#39;utf8&#39;);
  // creates a buffer containing UTF8 bytes [74, c3, a9, 73, 74]</code></pre>
<h2>Buffers and Character Encodings<span><a class="mark" href="buffer.html#buffer_buffers_and_character_encodings" id="buffer_buffers_and_character_encodings">#</a></span></h2>
<p>Buffers are commonly used to represent sequences of encoded characters
such as UTF8, UCS2, Base64 or even Hex-encoded data. It is possible to
convert back and forth between Buffers and ordinary JavaScript string objects
by using an explicit encoding method.

</p>
<pre><code class="js">const buf = new Buffer(&#39;hello world&#39;, &#39;ascii&#39;);
console.log(buf.toString(&#39;hex&#39;));
  // prints: 68656c6c6f20776f726c64
console.log(buf.toString(&#39;base64&#39;));
  // prints: aGVsbG8gd29ybGQ=</code></pre>
<p>The character encodings currently supported by Node.js include:

</p>
<ul>
<li><p><code>&#39;ascii&#39;</code> - for 7-bit ASCII data only.  This encoding method is very fast and
will strip the high bit if set.</p>
</li>
<li><p><code>&#39;utf8&#39;</code> - Multibyte encoded Unicode characters. Many web pages and other
document formats use UTF-8.</p>
</li>
<li><p><code>&#39;utf16le&#39;</code> - 2 or 4 bytes, little-endian encoded Unicode characters.
Surrogate pairs (U+10000 to U+10FFFF) are supported.</p>
</li>
<li><p><code>&#39;ucs2&#39;</code> - Alias of <code>&#39;utf16le&#39;</code>.</p>
</li>
<li><p><code>&#39;base64&#39;</code> - Base64 string encoding.</p>
</li>
<li><p><code>&#39;binary&#39;</code> - A way of encoding the buffer into a one-byte (<code>latin-1</code>)
encoded string. The string <code>&#39;latin-1&#39;</code> is not supported. Instead, pass
<code>&#39;binary&#39;</code> to use <code>&#39;latin-1&#39;</code> encoding.</p>
</li>
<li><p><code>&#39;hex&#39;</code> - Encode each byte as two hexadecimal characters.</p>
</li>
</ul>
<h2>Buffers and TypedArray<span><a class="mark" href="buffer.html#buffer_buffers_and_typedarray" id="buffer_buffers_and_typedarray">#</a></span></h2>
<p>Buffers are also <code>Uint8Array</code> TypedArray instances. However, there are subtle
incompatibilities with the TypedArray specification in ECMAScript 2015. For
instance, while <code>ArrayBuffer#slice()</code> creates a copy of the slice,
the implementation of <a href="buffer.html#buffer_buf_slice_start_end"><code>Buffer#slice()</code></a> creates a view over the
existing Buffer without copying, making <code>Buffer#slice()</code> far more efficient.

</p>
<p>It is also possible to create new TypedArray instances from a <code>Buffer</code> with the
following caveats:

</p>
<ol>
<li><p>The Buffer instances&#39;s memory is copied to the TypedArray, not shared.</p>
</li>
<li><p>The Buffer&#39;s memory is interpreted as an array of distinct elements, and not
as a byte array of the target type. That is,
<code>new Uint32Array(new Buffer([1,2,3,4]))</code> creates a 4-element <code>Uint32Array</code>
with elements <code>[1,2,3,4]</code>, not a <code>Uint32Array</code> with a single element
<code>[0x1020304]</code> or <code>[0x4030201]</code>.</p>
</li>
</ol>
<p>It is possible to create a new Buffer that shares the same allocated memory as
a TypedArray instance by using the TypeArray objects <code>.buffer</code> property:

</p>
<pre><code class="js">const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf1 = new Buffer(arr); // copies the buffer
const buf2 = new Buffer(arr.buffer); // shares the memory with arr;

console.log(buf1);
  // Prints: &lt;Buffer 88 a0&gt;, copied buffer has only two elements
console.log(buf2);
  // Prints: &lt;Buffer 88 13 a0 0f&gt;

arr[1] = 6000;
console.log(buf1);
  // Prints: &lt;Buffer 88 a0&gt;
console.log(buf2);
  // Prints: &lt;Buffer 88 13 70 17&gt;</code></pre>
<p>Note that when creating a Buffer using the TypeArray&#39;s <code>.buffer</code>, it is not
currently possible to use only a portion of the underlying <code>ArrayBuffer</code>. To
create a Buffer that uses only a part of the <code>ArrayBuffer</code>, use the
<a href="buffer.html#buffer_buf_slice_start_end"><code>buf.slice()</code></a> function after the Buffer is created:

</p>
<pre><code class="js">const arr = new Uint16Array(20);
const buf = new Buffer(arr.buffer).slice(0, 16);
console.log(buf.length);
  // Prints: 16</code></pre>
<h2>Buffers and ES6 iteration<span><a class="mark" href="buffer.html#buffer_buffers_and_es6_iteration" id="buffer_buffers_and_es6_iteration">#</a></span></h2>
<p>Buffers can be iterated over using the ECMAScript 2015 (ES6) <code>for..of</code> syntax:

</p>
<pre><code class="js">const buf = new Buffer([1, 2, 3]);

for (var b of buf)
  console.log(b)

// Prints:
//   1
//   2
//   3</code></pre>
<p>Additionally, the <a href="buffer.html#buffer_buf_values"><code>buf.values()</code></a>, <a href="buffer.html#buffer_buf_keys"><code>buf.keys()</code></a>, and
<a href="buffer.html#buffer_buf_entries"><code>buf.entries()</code></a> methods can be used to create iterators.

</p>
<h2>Class: Buffer<span><a class="mark" href="buffer.html#buffer_class_buffer" id="buffer_class_buffer">#</a></span></h2>
<p>The Buffer class is a global type for dealing with binary data directly.
It can be constructed in a variety of ways.

</p>
<h3>new Buffer(array)<span><a class="mark" href="buffer.html#buffer_new_buffer_array" id="buffer_new_buffer_array">#</a></span></h3>
<div class="signature"><ul>
<li><code>array</code> <span class="type">Array</span></li>
</div></ul>
<p>Allocates a new Buffer using an <code>array</code> of octets.

</p>
<pre><code class="js">const buf = new Buffer([0x62,0x75,0x66,0x66,0x65,0x72]);
  // creates a new Buffer containing ASCII bytes
  // [&#39;b&#39;,&#39;u&#39;,&#39;f&#39;,&#39;f&#39;,&#39;e&#39;,&#39;r&#39;]</code></pre>
<h3>new Buffer(buffer)<span><a class="mark" href="buffer.html#buffer_new_buffer_buffer" id="buffer_new_buffer_buffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>buffer</code> <span class="type">Buffer</span></li>
</div></ul>
<p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.

</p>
<pre><code class="js">const buf1 = new Buffer(&#39;buffer&#39;);
const buf2 = new Buffer(buf1);

buf1[0] = 0x61;
console.log(buf1.toString());
  // &#39;auffer&#39;
console.log(buf2.toString());
  // &#39;buffer&#39; (copy is not changed)</code></pre>
<h3>new Buffer(arrayBuffer)<span><a class="mark" href="buffer.html#buffer_new_buffer_arraybuffer" id="buffer_new_buffer_arraybuffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>arrayBuffer</code> - The <code>.buffer</code> property of a <code>TypedArray</code> or a <code>new
ArrayBuffer()</code></li>
</div></ul>
<p>When passed a reference to the <code>.buffer</code> property of a <code>TypedArray</code> instance,
the newly created Buffer will share the same allocated memory as the
TypedArray.

</p>
<pre><code class="js">const arr = new Uint16Array(2);
arr[0] = 5000;
arr[1] = 4000;

const buf = new Buffer(arr.buffer); // shares the memory with arr;

console.log(buf);
  // Prints: &lt;Buffer 88 13 a0 0f&gt;

// changing the TypdArray changes the Buffer also
arr[1] = 6000;

console.log(buf);
  // Prints: &lt;Buffer 88 13 70 17&gt;</code></pre>
<h3>new Buffer(size)<span><a class="mark" href="buffer.html#buffer_new_buffer_size" id="buffer_new_buffer_size">#</a></span></h3>
<div class="signature"><ul>
<li><code>size</code> <span class="type">Number</span></li>
</div></ul>
<p>Allocates a new Buffer of <code>size</code> bytes.  The <code>size</code> must be less than
or equal to the value of <code>require(&#39;buffer&#39;).kMaxLength</code> (on 64-bit
architectures, <code>kMaxLength</code> is <code>(2^31)-1</code>). Otherwise, a <a href="errors.html#errors_class_rangeerror"><code>RangeError</code></a> is
thrown. If a <code>size</code> less than 0 is specified, a zero-length Buffer will be
created.

</p>
<p>Unlike <code>ArrayBuffers</code>, the underlying memory for Buffer instances created in
this way is not initialized. The contents of a newly created <code>Buffer</code> are
unknown and could contain sensitive data. Use <a href="buffer.html#buffer_buf_fill_value_offset_end"><code>buf.fill(0)</code></a> to initialize a
Buffer to zeroes.

</p>
<pre><code class="js">const buf = new Buffer(5);
console.log(buf);
  // &lt;Buffer 78 e0 82 02 01&gt;
  // (octets will be different, every time)
buf.fill(0);
console.log(buf);
  // &lt;Buffer 00 00 00 00 00&gt;</code></pre>
<h3>new Buffer(str[, encoding])<span><a class="mark" href="buffer.html#buffer_new_buffer_str_encoding" id="buffer_new_buffer_str_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>str</code> <span class="type">String</span> String to encode.</li>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
</div></ul>
<p>Creates a new Buffer containing the given JavaScript string <code>str</code>. If
provided, the <code>encoding</code> parameter identifies the strings character encoding.

</p>
<pre><code class="js">const buf1 = new Buffer(&#39;this is a tést&#39;);
console.log(buf1.toString());
  // prints: this is a tést
console.log(buf1.toString(&#39;ascii&#39;));
  // prints: this is a tC)st

const buf2 = new Buffer(&#39;7468697320697320612074c3a97374&#39;, &#39;hex&#39;);
console.log(buf2.toString());
  // prints: this is a tést</code></pre>
<h3>Class Method: Buffer.byteLength(string[, encoding])<span><a class="mark" href="buffer.html#buffer_class_method_buffer_bytelength_string_encoding" id="buffer_class_method_buffer_bytelength_string_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>string</code> <span class="type">String</span></li>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Returns the actual byte length of a string. This is not the same as
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length"><code>String.prototype.length</code></a> since that returns the number of <em>characters</em> in
a string.

</p>
<p>Example:

</p>
<pre><code class="js">const str = &#39;\u00bd + \u00bc = \u00be&#39;;

console.log(`${str}: ${str.length} characters, ` +
            `${Buffer.byteLength(str, &#39;utf8&#39;)} bytes`);

// ½ + ¼ = ¾: 9 characters, 12 bytes</code></pre>
<h3>Class Method: Buffer.compare(buf1, buf2)<span><a class="mark" href="buffer.html#buffer_class_method_buffer_compare_buf1_buf2" id="buffer_class_method_buffer_compare_buf1_buf2">#</a></span></h3>
<div class="signature"><ul>
<li><code>buf1</code> <span class="type">Buffer</span></li>
<li><code>buf2</code> <span class="type">Buffer</span></li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Compares <code>buf1</code> to <code>buf2</code> typically for the purpose of sorting arrays of
Buffers. This is equivalent is calling <a href="buffer.html#buffer_buf_compare_otherbuffer"><code>buf1.compare(buf2)</code></a>.

</p>
<pre><code class="js">const arr = [Buffer(&#39;1234&#39;), Buffer(&#39;0123&#39;)];
arr.sort(Buffer.compare);</code></pre>
<h3>Class Method: Buffer.concat(list[, totalLength])<span><a class="mark" href="buffer.html#buffer_class_method_buffer_concat_list_totallength" id="buffer_class_method_buffer_concat_list_totallength">#</a></span></h3>
<div class="signature"><ul>
<li><code>list</code> <span class="type">Array</span> List of Buffer objects to concat</li>
<li><code>totalLength</code> <span class="type">Number</span> Total length of the Buffers in the list when concatenated</li>
<li>Return: <span class="type">Buffer</span></li>
</div></ul>
<p>Returns a new Buffer which is the result of concatenating all the Buffers in
the <code>list</code> together.

</p>
<p>If the list has no items, or if the <code>totalLength</code> is 0, then a new zero-length
Buffer is returned.

</p>
<p>If <code>totalLength</code> is not provided, it is calculated from the Buffers in the
<code>list</code>. This, however, adds an additional loop to the function, so it is faster
to provide the length explicitly.

</p>
<p>Example: build a single Buffer from a list of three Buffers:

</p>
<pre><code class="js">const buf1 = new Buffer(10).fill(0);
const buf2 = new Buffer(14).fill(0);
const buf3 = new Buffer(18).fill(0);
const totalLength = buf1.length + buf2.length + buf3.length;

console.log(totalLength);
const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
console.log(bufA);
console.log(bufA.length);

// 42
// &lt;Buffer 00 00 00 00 ...&gt;
// 42</code></pre>
<h3>Class Method: Buffer.isBuffer(obj)<span><a class="mark" href="buffer.html#buffer_class_method_buffer_isbuffer_obj" id="buffer_class_method_buffer_isbuffer_obj">#</a></span></h3>
<div class="signature"><ul>
<li><code>obj</code> <span class="type">Object</span></li>
<li>Return: <span class="type">Boolean</span></li>
</div></ul>
<p>Returns &#39;true&#39; if <code>obj</code> is a Buffer.

</p>
<h3>Class Method: Buffer.isEncoding(encoding)<span><a class="mark" href="buffer.html#buffer_class_method_buffer_isencoding_encoding" id="buffer_class_method_buffer_isencoding_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>encoding</code> <span class="type">String</span> The encoding string to test</li>
<li>Return: <span class="type">Boolean</span></li>
</div></ul>
<p>Returns true if the <code>encoding</code> is a valid encoding argument, or false
otherwise.

</p>
<h3>buf[index]<span><a class="mark" href="buffer.html#buffer_buf_index" id="buffer_buf_index">#</a></span></h3>
<!--type=property-->
<!--name=[index]-->

<p>The index operator <code>[index]</code> can be used to get and set the octet at position
<code>index</code> in the Buffer. The values refer to individual bytes, so the legal value
range is between <code>0x00</code> and <code>0xFF</code> (hex) or <code>0</code> and <code>255</code> (decimal).

</p>
<p>Example: copy an ASCII string into a Buffer, one byte at a time:

</p>
<pre><code class="js">const str = &quot;Node.js&quot;;
const buf = new Buffer(str.length);

for (var i = 0; i &lt; str.length ; i++) {
  buf[i] = str.charCodeAt(i);
}

console.log(buf);
  // Prints: Node.js</code></pre>
<h3>buf.compare(otherBuffer)<span><a class="mark" href="buffer.html#buffer_buf_compare_otherbuffer" id="buffer_buf_compare_otherbuffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>otherBuffer</code> <span class="type">Buffer</span></li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Compares two Buffer instances and returns a number indicating whether <code>buf</code>
comes before, after, or is the same as the <code>otherBuffer</code> in sort order.
Comparison is based on the actual sequence of bytes in each Buffer.

</p>
<ul>
<li><code>0</code> is returned if <code>otherBuffer</code> is the same as <code>buf</code></li>
<li><code>1</code> is returned if <code>otherBuffer</code> should come <em>before</em> <code>buf</code> when sorted.</li>
<li><code>-1</code> is returned if <code>otherBuffer</code> should come <em>after</em> <code>buf</code> when sorted.</li>
</ul>
<pre><code class="js">const buf1 = new Buffer(&#39;ABC&#39;);
const buf2 = new Buffer(&#39;BCD&#39;);
const buf3 = new Buffer(&#39;ABCD&#39;);

console.log(buf1.compare(buf1));
  // Prints: 0
console.log(buf1.compare(buf2));
  // Prints: -1
console.log(buf1.compare(buf3));
  // Prints: 1
console.log(buf2.compare(buf1));
  // Prints: 1
console.log(buf2.compare(buf3));
  // Prints: 1

[buf1, buf2, buf3].sort(Buffer.compare);
  // produces sort order [buf1, buf3, buf2]</code></pre>
<h3>buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])<span><a class="mark" href="buffer.html#buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend" id="buffer_buf_copy_targetbuffer_targetstart_sourcestart_sourceend">#</a></span></h3>
<div class="signature"><ul>
<li><code>targetBuffer</code> <span class="type">Buffer</span> Buffer to copy into</li>
<li><code>targetStart</code> <span class="type">Number</span> Default: 0</li>
<li><code>sourceStart</code> <span class="type">Number</span> Default: 0</li>
<li><code>sourceEnd</code> <span class="type">Number</span> Default: <code>buffer.length</code></li>
<li>Return: <span class="type">Number</span> The number of bytes copied.</li>
</div></ul>
<p>Copies data from a region of this Buffer to a region in the target Buffer even
if the target memory region overlaps with the source.

</p>
<p>Example: build two Buffers, then copy <code>buf1</code> from byte 16 through byte 19
into <code>buf2</code>, starting at the 8th byte in <code>buf2</code>.

</p>
<pre><code class="js">const buf1 = new Buffer(26);
const buf2 = new Buffer(26).fill(&#39;!&#39;);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf1[i] = i + 97; // 97 is ASCII a
}

buf1.copy(buf2, 8, 16, 20);
console.log(buf2.toString(&#39;ascii&#39;, 0, 25));
  // Prints: !!!!!!!!qrst!!!!!!!!!!!!!</code></pre>
<p>Example: Build a single Buffer, then copy data from one region to an overlapping
region in the same Buffer

</p>
<pre><code class="js">const buf = new Buffer(26);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}

buf.copy(buf, 0, 4, 10);
console.log(buf.toString());

// efghijghijklmnopqrstuvwxyz</code></pre>
<h3>buf.entries()<span><a class="mark" href="buffer.html#buffer_buf_entries" id="buffer_buf_entries">#</a></span></h3>
<div class="signature"><ul>
<li>Return: <span class="type">Iterator</span></li>
</div></ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> of <code>[index, byte]</code> pairs from the Buffer
contents.

</p>
<pre><code class="js">const buf = new Buffer(&#39;buffer&#39;);
for (var pair of buf.entries()) {
  console.log(pair);
}
// prints:
//   [0, 98]
//   [1, 117]
//   [2, 102]
//   [3, 102]
//   [4, 101]
//   [5, 114]</code></pre>
<h3>buf.equals(otherBuffer)<span><a class="mark" href="buffer.html#buffer_buf_equals_otherbuffer" id="buffer_buf_equals_otherbuffer">#</a></span></h3>
<div class="signature"><ul>
<li><code>otherBuffer</code> <span class="type">Buffer</span></li>
<li>Return: <span class="type">Boolean</span></li>
</div></ul>
<p>Returns a boolean indicating whether <code>this</code> and <code>otherBuffer</code> have exactly the
same bytes.

</p>
<pre><code class="js">const buf1 = new Buffer(&#39;ABC&#39;);
const buf2 = new Buffer(&#39;414243&#39;, &#39;hex&#39;);
const buf3 = new Buffer(&#39;ABCD&#39;);

console.log(buf1.equals(buf2));
  // Prints: true
console.log(buf1.equals(buf3));
  // Prints: false</code></pre>
<h3>buf.fill(value[, offset[, end]])<span><a class="mark" href="buffer.html#buffer_buf_fill_value_offset_end" id="buffer_buf_fill_value_offset_end">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <span class="type">String or Number</span></li>
<li><code>offset</code> <span class="type">Number</span> Default: 0</li>
<li><code>end</code> <span class="type">Number</span> Default: <code>buffer.length</code></li>
<li>Return: <span class="type">Buffer</span></li>
</div></ul>
<p>Fills the Buffer with the specified value. If the <code>offset</code> and <code>end</code> are not
given it will fill the entire Buffer. The method returns a reference to the
Buffer so calls can be chained.

</p>
<pre><code class="js">const b = new Buffer(50).fill(&#39;h&#39;);
console.log(b.toString());
  // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</code></pre>
<h3>buf.indexOf(value[, byteOffset][, encoding])<span><a class="mark" href="buffer.html#buffer_buf_indexof_value_byteoffset_encoding" id="buffer_buf_indexof_value_byteoffset_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <span class="type">String, Buffer or Number</span></li>
<li><code>byteOffset</code> <span class="type">Number</span> Default: 0</li>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Operates similar to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf"><code>Array#indexOf()</code></a> in that it returns either the
starting index position of <code>value</code> in Buffer or <code>-1</code> if the Buffer does not
contain <code>value</code>. The <code>value</code> can be a String, Buffer or Number. Strings are by
default interpreted as UTF8. Buffers will use the entire Buffer (to compare a
partial Buffer use <a href="buffer.html#buffer_buf_slice_start_end"><code>buf.slice()</code></a>).  Numbers can range from 0 to 255.

</p>
<pre><code class="js">const buf = new Buffer(&#39;this is a buffer&#39;);

buf.indexOf(&#39;this&#39;);
  // returns 0
buf.indexOf(&#39;is&#39;);
  // returns 2
buf.indexOf(new Buffer(&#39;a buffer&#39;));
  // returns 8
buf.indexOf(97); // ascii for &#39;a&#39;
  // returns 8
buf.indexOf(new Buffer(&#39;a buffer example&#39;));
  // returns -1
buf.indexOf(new Buffer(&#39;a buffer example&#39;).slice(0,8));
  // returns 8

const utf16Buffer = new Buffer(&#39;\u039a\u0391\u03a3\u03a3\u0395&#39;, &#39;ucs2&#39;);

utf16Buffer.indexOf(&#39;\u03a3&#39;,  0, &#39;ucs2&#39;);
  // returns 4
utf16Buffer.indexOf(&#39;\u03a3&#39;, -4, &#39;ucs2&#39;);
  // returns 6</code></pre>
<h3>buf.includes(value[, byteOffset][, encoding])<span><a class="mark" href="buffer.html#buffer_buf_includes_value_byteoffset_encoding" id="buffer_buf_includes_value_byteoffset_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <span class="type">String, Buffer or Number</span></li>
<li><code>byteOffset</code> <span class="type">Number</span> Default: 0</li>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
<li>Return: <span class="type">Boolean</span></li>
</div></ul>
<p>Operates similar to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes"><code>Array#includes()</code></a>. The <code>value</code> can be a String, Buffer
or Number. Strings are interpreted as UTF8 unless overridden with the
<code>encoding</code> argument. Buffers will use the entire Buffer (to compare a partial
Buffer use <a href="buffer.html#buffer_buf_slice_start_end"><code>buf.slice()</code></a>). Numbers can range from 0 to 255.

</p>
<p>The <code>byteOffset</code> indicates the index in <code>buf</code> where searching begins.

</p>
<pre><code class="js">const buf = new Buffer(&#39;this is a buffer&#39;);

buf.includes(&#39;this&#39;);
  // returns true
buf.includes(&#39;is&#39;);
  // returns true
buf.includes(new Buffer(&#39;a buffer&#39;));
  // returns true
buf.includes(97); // ascii for &#39;a&#39;
  // returns true
buf.includes(new Buffer(&#39;a buffer example&#39;));
  // returns false
buf.includes(new Buffer(&#39;a buffer example&#39;).slice(0,8));
  // returns true
buf.includes(&#39;this&#39;, 4);
  // returns false</code></pre>
<h3>buf.keys()<span><a class="mark" href="buffer.html#buffer_buf_keys" id="buffer_buf_keys">#</a></span></h3>
<div class="signature"><ul>
<li>Return: <span class="type">Iterator</span></li>
</div></ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> of Buffer keys (indices).

</p>
<pre><code class="js">const buf = new Buffer(&#39;buffer&#39;);
for (var key of buf.keys()) {
  console.log(key);
}
// prints:
//   0
//   1
//   2
//   3
//   4
//   5</code></pre>
<h3>buf.length<span><a class="mark" href="buffer.html#buffer_buf_length" id="buffer_buf_length">#</a></span></h3>
<div class="signature"><ul>
<li><span class="type">Number</span></li>
</div></ul>
<p>Returns the amount of memory allocated for the Buffer in number of bytes. Note
that this does not necessarily reflect the amount of usable data within the
Buffer. For instance, in the example below, a Buffer with 1234 bytes is
allocated, but only 11 ASCII bytes are written.

</p>
<pre><code class="js">const buf = new Buffer(1234);

console.log(buf.length);
  // Prints: 1234

buf.write(&#39;some string&#39;, 0, &#39;ascii&#39;);
console.log(buf.length);
  // Prints: 1234</code></pre>
<p>While the <code>length</code> property is not immutable, changing the value of <code>length</code>
can result in undefined and inconsistent behavior. Applications that wish to
modify the length of a Buffer should therefore treat <code>length</code> as read-only and
use <a href="buffer.html#buffer_buf_slice_start_end"><code>buf.slice()</code></a> to create a new Buffer.

</p>
<pre><code class="js">const buf = new Buffer(10);
buf.write(&#39;abcdefghj&#39;, 0, &#39;ascii&#39;);
console.log(buf.length);
  // Prints: 10
buf = buf.slice(0,5);
console.log(buf.length);
  // Prints: 5</code></pre>
<h3>buf.readDoubleBE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readdoublebe_offset_noassert" id="buffer_buf_readdoublebe_offset_noassert">#</a></span></h3>
<h3>buf.readDoubleLE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readdoublele_offset_noassert" id="buffer_buf_readdoublele_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 8</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads a 64-bit double from the Buffer at the specified <code>offset</code> with specified
endian format (<code>readDoubleBE()</code> returns big endian, <code>readDoubleLE()</code> returns
little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<pre><code class="js">const buf = new Buffer([1,2,3,4,5,6,7,8]);

buf.readDoubleBE();
  // Returns: 8.20788039913184e-304
buf.readDoubleLE();
  // Returns: 5.447603722011605e-270
buf.readDoubleLE(1);
  // throws RangeError: Index out of range

buf.readDoubleLE(1, true); // Warning: reads passed end of buffer!
  // Segmentation fault! don&#39;t do this!</code></pre>
<h3>buf.readFloatBE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readfloatbe_offset_noassert" id="buffer_buf_readfloatbe_offset_noassert">#</a></span></h3>
<h3>buf.readFloatLE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readfloatle_offset_noassert" id="buffer_buf_readfloatle_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads a 32-bit float from the Buffer at the specified <code>offset</code> with specified
endian format (<code>readFloatBE()</code> returns big endian, <code>readFloatLE()</code> returns
little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<pre><code class="js">const buf = new Buffer([1,2,3,4]);

buf.readFloatBE();
  // Returns: 2.387939260590663e-38
buf.readFloatLE();
  // Returns: 1.539989614439558e-36
buf.readFloatLE(1);
  // throws RangeError: Index out of range

buf.readFloatLE(1, true); // Warning: reads passed end of buffer!
  // Segmentation fault! don&#39;t do this!</code></pre>
<h3>buf.readInt8(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readint8_offset_noassert" id="buffer_buf_readint8_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <span class="type">Number</span> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <span class="type">Boolean</span> Default: false</li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Reads a signed 8-bit integer from the Buffer at the specified <code>offset</code>.

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.

</p>
<pre><code class="js">const buf = new Buffer([1,-2,3,4]);

buf.readInt8(0);
  // returns 1
buf.readInt8(1);
  // returns -2</code></pre>
<h3>buf.readInt16BE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readint16be_offset_noassert" id="buffer_buf_readint16be_offset_noassert">#</a></span></h3>
<h3>buf.readInt16LE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readint16le_offset_noassert" id="buffer_buf_readint16le_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads a signed 16-bit integer from the Buffer at the specified <code>offset</code> with
the specified endian format (<code>readInt16BE()</code> returns big endian,
<code>readInt16LE()</code> returns little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.

</p>
<pre><code class="js">const buf = new Buffer([1,-2,3,4]);

buf.readInt16BE();
  // returns 510
buf.readInt16LE(1);
  // returns -511</code></pre>
<h3>buf.readInt32BE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readint32be_offset_noassert" id="buffer_buf_readint32be_offset_noassert">#</a></span></h3>
<h3>buf.readInt32LE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readint32le_offset_noassert" id="buffer_buf_readint32le_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads a signed 32-bit integer from the Buffer at the specified <code>offset</code> with
the specified endian format (<code>readInt32BE()</code> returns big endian,
<code>readInt32LE()</code> returns little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<p>Integers read from the Buffer are interpreted as two&#39;s complement signed values.

</p>
<pre><code class="js">const buf = new Buffer([1,-2,3,4]);

buf.readInt32BE();
  // returns 33424132
buf.readInt32LE(1);
  // returns 67370497</code></pre>
<h3>buf.readIntBE(offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readintbe_offset_bytelength_noassert" id="buffer_buf_readintbe_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.readIntLE(offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readintle_offset_bytelength_noassert" id="buffer_buf_readintle_offset_bytelength_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> {Number} <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads <code>byteLength</code> number of bytes from the Buffer at the specified <code>offset</code>
and interprets the result as a two&#39;s complement signed value. Supports up to 48
bits of accuracy. For example:

</p>
<pre><code class="js">const buf = new Buffer(6);
buf.writeUInt16LE(0x90ab, 0);
buf.writeUInt32LE(0x12345678, 2);
buf.readIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)
// Returns: &#39;1234567890ab&#39;

buf.readIntBE(0, 6).toString(16);
// Returns: -546f87a9cbee</code></pre>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<h3>buf.readUInt8(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuint8_offset_noassert" id="buffer_buf_readuint8_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>offset</code> <span class="type">Number</span> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <span class="type">Boolean</span> Default: false</li>
<li>Return: <span class="type">Number</span></li>
</div></ul>
<p>Reads an unsigned 8-bit integer from the Buffer at the specified <code>offset</code>.

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<pre><code class="js">const buf = new Buffer([1,-2,3,4]);

buf.readUInt8(0);
  // returns 1
buf.readUInt8(1);
  // returns 254</code></pre>
<h3>buf.readUInt16BE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuint16be_offset_noassert" id="buffer_buf_readuint16be_offset_noassert">#</a></span></h3>
<h3>buf.readUInt16LE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuint16le_offset_noassert" id="buffer_buf_readuint16le_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads an unsigned 16-bit integer from the Buffer at the specified <code>offset</code> with
specified endian format (<code>readInt32BE()</code> returns big endian,
<code>readInt32LE()</code> returns little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);

buf.readUInt16BE(0);
  // Returns: 0x0304
buf.readUInt16LE(0);
  // Returns: 0x0403
buf.readUInt16BE(1);
  // Returns: 0x0423
buf.readUInt16LE(1);
  // Returns: 0x2304
buf.readUInt16BE(2);
  // Returns: 0x2342
buf.readUInt16LE(2);
  // Returns: 0x4223</code></pre>
<h3>buf.readUInt32BE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuint32be_offset_noassert" id="buffer_buf_readuint32be_offset_noassert">#</a></span></h3>
<h3>buf.readUInt32LE(offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuint32le_offset_noassert" id="buffer_buf_readuint32le_offset_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads an unsigned 32-bit integer from the Buffer at the specified <code>offset</code> with
specified endian format (<code>readInt32BE()</code> returns big endian,
<code>readInt32LE()</code> returns little endian).

</p>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer([0x3, 0x4, 0x23, 0x42]);

buf.readUInt32BE(0);
  // Returns: 0x03042342
console.log(buf.readUInt32LE(0));
  // Returns: 0x42230403</code></pre>
<h3>buf.readUIntBE(offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuintbe_offset_bytelength_noassert" id="buffer_buf_readuintbe_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.readUIntLE(offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_readuintle_offset_bytelength_noassert" id="buffer_buf_readuintle_offset_bytelength_noassert">#</a></span></h3>
<ul>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> {Number} <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number}</li>
</ul>
<p>Reads <code>byteLength</code> number of bytes from the Buffer at the specified <code>offset</code>
and interprets the result as an unsigned integer. Supports up to 48
bits of accuracy. For example:

</p>
<pre><code class="js">const buf = new Buffer(6);
buf.writeUInt16LE(0x90ab, 0);
buf.writeUInt32LE(0x12345678, 2);
buf.readUIntLE(0, 6).toString(16);  // Specify 6 bytes (48 bits)
// Returns: &#39;1234567890ab&#39;

buf.readUIntBE(0, 6).toString(16);
// Returns: ab9078563412</code></pre>
<p>Setting <code>noAssert</code> to <code>true</code> skips validation of the <code>offset</code>. This allows the
<code>offset</code> to be beyond the end of the Buffer.

</p>
<h3>buf.slice([start[, end]])<span><a class="mark" href="buffer.html#buffer_buf_slice_start_end" id="buffer_buf_slice_start_end">#</a></span></h3>
<div class="signature"><ul>
<li><code>start</code> <span class="type">Number</span> Default: 0</li>
<li><code>end</code> <span class="type">Number</span> Default: <code>buffer.length</code></li>
<li>Return: <span class="type">Buffer</span></li>
</div></ul>
<p>Returns a new Buffer that references the same memory as the original, but
offset and cropped by the <code>start</code> and <code>end</code> indices.

</p>
<p><strong>Note that modifying the new Buffer slice will modify the memory in the
original Buffer because the allocated memory of the two objects overlap.</strong>

</p>
<p>Example: build a Buffer with the ASCII alphabet, take a slice, then modify one
byte from the original Buffer.

</p>
<pre><code class="js">const buf1 = new Buffer(26);

for (var i = 0 ; i &lt; 26 ; i++) {
  buf1[i] = i + 97; // 97 is ASCII a
}

const buf2 = buf1.slice(0, 3);
buf2.toString(&#39;ascii&#39;, 0, buf2.length);
  // Returns: &#39;abc&#39;
buf1[0] = 33;
buf2.toString(&#39;ascii&#39;, 0, buf2.length);
  // Returns : &#39;!bc&#39;</code></pre>
<p>Specifying negative indexes causes the slice to be generated relative to the
end of the Buffer rather than the beginning.

</p>
<pre><code class="js">const buf = new Buffer(&#39;buffer&#39;);

buf.slice(-6, -1).toString();
  // Returns &#39;buffe&#39;, equivalent to buf.slice(0, 5)
buf.slice(-6, -2).toString();
  // Returns &#39;buff&#39;, equivalent to buf.slice(0, 4)
buf.slice(-5, -2).toString();
  // Returns &#39;uff&#39;, equivalent to buf.slice(1, 4)</code></pre>
<h3>buf.toString([encoding[, start[, end]]])<span><a class="mark" href="buffer.html#buffer_buf_tostring_encoding_start_end" id="buffer_buf_tostring_encoding_start_end">#</a></span></h3>
<div class="signature"><ul>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
<li><code>start</code> <span class="type">Number</span> Default: 0</li>
<li><code>end</code> <span class="type">Number</span> Default: <code>buffer.length</code></li>
<li>Return: <span class="type">String</span></li>
</div></ul>
<p>Decodes and returns a string from the Buffer data using the specified
character set <code>encoding</code>.

</p>
<pre><code class="js">const buf = new Buffer(26);
for (var i = 0 ; i &lt; 26 ; i++) {
  buf[i] = i + 97; // 97 is ASCII a
}
buf.toString(&#39;ascii&#39;);
  // Returns: &#39;abcdefghijklmnopqrstuvwxyz&#39;
buf.toString(&#39;ascii&#39;,0,5);
  // Returns: &#39;abcde&#39;
buf.toString(&#39;utf8&#39;,0,5);
  // Returns: &#39;abcde&#39;
buf.toString(undefined,0,5);
  // Returns: &#39;abcde&#39;, encoding defaults to &#39;utf8&#39;</code></pre>
<h3>buf.toJSON()<span><a class="mark" href="buffer.html#buffer_buf_tojson" id="buffer_buf_tojson">#</a></span></h3>
<div class="signature"><ul>
<li>Return: <span class="type">Object</span></li>
</div></ul>
<p>Returns a JSON representation of the Buffer instance.  <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify"><code>JSON.stringify()</code></a>
implicitly calls this function when stringifying a Buffer instance.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(&#39;test&#39;);
const json = JSON.stringify(buf);

console.log(json);
// Prints: &#39;{&quot;type&quot;:&quot;Buffer&quot;,&quot;data&quot;:[116,101,115,116]}&#39;

const copy = JSON.parse(json, (key, value) =&gt; {
    return value &amp;&amp; value.type === &#39;Buffer&#39;
      ? new Buffer(value.data)
      : value;
  });

console.log(copy.toString());
// Prints: &#39;test&#39;</code></pre>
<h3>buf.values()<span><a class="mark" href="buffer.html#buffer_buf_values" id="buffer_buf_values">#</a></span></h3>
<div class="signature"><ul>
<li>Return: <span class="type">Iterator</span></li>
</div></ul>
<p>Creates and returns an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols">iterator</a> for Buffer values (bytes). This function is
called automatically when the Buffer is used in a <code>for..of</code> statement.

</p>
<pre><code class="js">const buf = new Buffer(&#39;buffer&#39;);
for (var value of buf.values()) {
  console.log(value);
}
// prints:
//   98
//   117
//   102
//   102
//   101
//   114

for (var value of buf) {
  console.log(value);
}
// prints:
//   98
//   117
//   102
//   102
//   101
//   114</code></pre>
<h3>buf.write(string[, offset[, length]][, encoding])<span><a class="mark" href="buffer.html#buffer_buf_write_string_offset_length_encoding" id="buffer_buf_write_string_offset_length_encoding">#</a></span></h3>
<div class="signature"><ul>
<li><code>string</code> <span class="type">String</span> Bytes to be written to buffer</li>
<li><code>offset</code> <span class="type">Number</span> Default: 0</li>
<li><code>length</code> <span class="type">Number</span> Default: <code>buffer.length - offset</code></li>
<li><code>encoding</code> <span class="type">String</span> Default: <code>&#39;utf8&#39;</code></li>
<li>Return: <span class="type">Number</span> Numbers of bytes written</li>
</div></ul>
<p>Writes <code>string</code> to the Buffer at <code>offset</code> using the given <code>encoding</code>.
The <code>length</code> parameter is the number of bytes to write. If the Buffer did not
contain enough space to fit the entire string, only a partial amount of the
string will be written however, it will not write only partially encoded
characters.

</p>
<pre><code class="js">const buf = new Buffer(256);
const len = buf.write(&#39;\u00bd + \u00bc = \u00be&#39;, 0);
console.log(`${len} bytes: ${buf.toString(&#39;utf8&#39;, 0, len)}`);
  // Prints: 12 bytes: ½ + ¼ = ¾</code></pre>
<h3>buf.writeDoubleBE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writedoublebe_value_offset_noassert" id="buffer_buf_writedoublebe_value_offset_noassert">#</a></span></h3>
<h3>buf.writeDoubleLE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writedoublele_value_offset_noassert" id="buffer_buf_writedoublele_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 8</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeDoubleBE()</code> writes big endian, <code>writeDoubleLE()</code> writes little
endian). The <code>value</code> argument must be a valid 64-bit double.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(8);
buf.writeDoubleBE(0xdeadbeefcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer 43 eb d5 b7 dd f9 5f d7&gt;

buf.writeDoubleLE(0xdeadbeefcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer d7 5f f9 dd b7 d5 eb 43&gt;</code></pre>
<h3>buf.writeFloatBE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writefloatbe_value_offset_noassert" id="buffer_buf_writefloatbe_value_offset_noassert">#</a></span></h3>
<h3>buf.writeFloatLE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writefloatle_value_offset_noassert" id="buffer_buf_writefloatle_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeFloatBE()</code> writes big endian, <code>writeFloatLE()</code> writes little
endian). Behavior is unspecified if <code>value</code> is anything other than a 32-bit
float.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(4);
buf.writeFloatBE(0xcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer 4f 4a fe bb&gt;

buf.writeFloatLE(0xcafebabe, 0);

console.log(buf);
  // Prints: &lt;Buffer bb fe 4a 4f&gt;</code></pre>
<h3>buf.writeInt8(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeint8_value_offset_noassert" id="buffer_buf_writeint8_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <span class="type">Number</span> Bytes to be written to Buffer</li>
<li><code>offset</code> <span class="type">Number</span> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <span class="type">Boolean</span> Default: false</li>
<li>Return: <span class="type">Number</span> Numbers of bytes written</li>
</div></ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code>. The <code>value</code> must be a
valid signed 8-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.

</p>
<pre><code class="js">const buf = new Buffer(2);
buf.writeInt8(2, 0);
buf.writeInt8(-2, 1);
console.log(buf);
  // Prints: &lt;Buffer 02 fe&gt;</code></pre>
<h3>buf.writeInt16BE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeint16be_value_offset_noassert" id="buffer_buf_writeint16be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeInt16LE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeint16le_value_offset_noassert" id="buffer_buf_writeint16le_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeInt16BE()</code> writes big endian, <code>writeInt16LE()</code> writes little
endian). The <code>value</code> must be a valid signed 16-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.

</p>
<pre><code class="js">const buf = new Buffer(4);
buf.writeInt16BE(0x0102,0);
buf.writeInt16LE(0x0304,2);
console.log(buf);
  // Prints: &lt;Buffer 01 02 04 03&gt;</code></pre>
<h3>buf.writeInt32BE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeint32be_value_offset_noassert" id="buffer_buf_writeint32be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeInt32LE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeint32le_value_offset_noassert" id="buffer_buf_writeint32le_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeInt32BE()</code> writes big endian, <code>writeInt32LE()</code> writes little
endian). The <code>value</code> must be a valid signed 32-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>The <code>value</code> is interpreted and written as a two&#39;s complement signed integer.

</p>
<pre><code class="js">const buf = new Buffer(8);
buf.writeInt32BE(0x01020304,0);
buf.writeInt32LE(0x05060708,4);
console.log(buf);
  // Prints: &lt;Buffer 01 02 03 04 08 07 06 05&gt;</code></pre>
<h3>buf.writeIntBE(value, offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeintbe_value_offset_bytelength_noassert" id="buffer_buf_writeintbe_value_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.writeIntLE(value, offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeintle_value_offset_bytelength_noassert" id="buffer_buf_writeintle_value_offset_bytelength_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> {Number} <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> and <code>byteLength</code>.
Supports up to 48 bits of accuracy. For example:

</p>
<pre><code class="js">const buf1 = new Buffer(6);
buf1.writeUIntBE(0x1234567890ab, 0, 6);
console.log(buf1);
  // Prints: &lt;Buffer 12 34 56 78 90 ab&gt;

const buf2 = new Buffer(6);
buf2.writeUIntLE(0x1234567890ab, 0, 6);
console.log(buf2);
  // Prints: &lt;Buffer ab 90 78 56 34 12&gt;</code></pre>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<h3>buf.writeUInt8(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuint8_value_offset_noassert" id="buffer_buf_writeuint8_value_offset_noassert">#</a></span></h3>
<div class="signature"><ul>
<li><code>value</code> <span class="type">Number</span> Bytes to be written to Buffer</li>
<li><code>offset</code> <span class="type">Number</span> <code>0 &lt;= offset &lt;= buf.length - 1</code></li>
<li><code>noAssert</code> <span class="type">Boolean</span> Default: false</li>
<li>Return: <span class="type">Number</span> Numbers of bytes written</li>
</div></ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code>. The <code>value</code> must be a
valid unsigned 8-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(4);
buf.writeUInt8(0x3, 0);
buf.writeUInt8(0x4, 1);
buf.writeUInt8(0x23, 2);
buf.writeUInt8(0x42, 3);

console.log(buf);
  // Prints: &lt;Buffer 03 04 23 42&gt;</code></pre>
<h3>buf.writeUInt16BE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuint16be_value_offset_noassert" id="buffer_buf_writeuint16be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeUInt16LE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuint16le_value_offset_noassert" id="buffer_buf_writeuint16le_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 2</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeUInt16BE()</code> writes big endian, <code>writeUInt16LE()</code> writes little
endian). The <code>value</code> must be a valid unsigned 16-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(4);
buf.writeUInt16BE(0xdead, 0);
buf.writeUInt16BE(0xbeef, 2);

console.log(buf);
  // Prints: &lt;Buffer de ad be ef&gt;

buf.writeUInt16LE(0xdead, 0);
buf.writeUInt16LE(0xbeef, 2);

console.log(buf);
  // Prints: &lt;Buffer ad de ef be&gt;</code></pre>
<h3>buf.writeUInt32BE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuint32be_value_offset_noassert" id="buffer_buf_writeuint32be_value_offset_noassert">#</a></span></h3>
<h3>buf.writeUInt32LE(value, offset[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuint32le_value_offset_noassert" id="buffer_buf_writeuint32le_value_offset_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - 4</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> with specified endian
format (<code>writeUInt32BE()</code> writes big endian, <code>writeUInt32LE()</code> writes little
endian). The <code>value</code> must be a valid unsigned 32-bit integer.

</p>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<p>Example:

</p>
<pre><code class="js">const buf = new Buffer(4);
buf.writeUInt32BE(0xfeedface, 0);

console.log(buf);
  // Prints: &lt;Buffer fe ed fa ce&gt;

buf.writeUInt32LE(0xfeedface, 0);

console.log(buf);
  // Prints: &lt;Buffer ce fa ed fe&gt;</code></pre>
<h3>buf.writeUIntBE(value, offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuintbe_value_offset_bytelength_noassert" id="buffer_buf_writeuintbe_value_offset_bytelength_noassert">#</a></span></h3>
<h3>buf.writeUIntLE(value, offset, byteLength[, noAssert])<span><a class="mark" href="buffer.html#buffer_buf_writeuintle_value_offset_bytelength_noassert" id="buffer_buf_writeuintle_value_offset_bytelength_noassert">#</a></span></h3>
<ul>
<li><code>value</code> {Number} Bytes to be written to Buffer</li>
<li><code>offset</code> {Number} <code>0 &lt;= offset &lt;= buf.length - byteLength</code></li>
<li><code>byteLength</code> {Number} <code>0 &lt; byteLength &lt;= 6</code></li>
<li><code>noAssert</code> {Boolean} Default: false</li>
<li>Return: {Number} Numbers of bytes written</li>
</ul>
<p>Writes <code>value</code> to the Buffer at the specified <code>offset</code> and <code>byteLength</code>.
Supports up to 48 bits of accuracy. For example:

</p>
<pre><code class="js">const buf = new Buffer(6);
buf.writeUIntBE(0x1234567890ab, 0, 6);
console.log(buf);
  // Prints: &lt;Buffer 12 34 56 78 90 ab&gt;</code></pre>
<p>Set <code>noAssert</code> to true to skip validation of <code>value</code> and <code>offset</code>. This means
that <code>value</code> may be too large for the specific function and <code>offset</code> may be
beyond the end of the Buffer leading to the values being silently dropped. This
should not be used unless you are certain of correctness.

</p>
<h2>buffer.INSPECT_MAX_BYTES<span><a class="mark" href="buffer.html#buffer_buffer_inspect_max_bytes" id="buffer_buffer_inspect_max_bytes">#</a></span></h2>
<div class="signature"><ul>
<li><span class="type">Number</span> Default: 50</li>
</div></ul>
<p>Returns the maximum number of bytes that will be returned when
<code>buffer.inspect()</code> is called. This can be overridden by user modules. See
<a href="util.html#util_util_inspect_object_options"><code>util.inspect()</code></a> for more details on <code>buffer.inspect()</code> behavior.

</p>
<p>Note that this is a property on the <code>buffer</code> module as returned by
<code>require(&#39;buffer&#39;)</code>, not on the Buffer global or a Buffer instance.

</p>
<h2>Class: SlowBuffer<span><a class="mark" href="buffer.html#buffer_class_slowbuffer" id="buffer_class_slowbuffer">#</a></span></h2>
<p>Returns an un-pooled <code>Buffer</code>.

</p>
<p>In order to avoid the garbage collection overhead of creating many individually
allocated Buffers, by default allocations under 4KB are sliced from a single
larger allocated object. This approach improves both performance and memory
usage since v8 does not need to track and cleanup as many <code>Persistent</code> objects.

</p>
<p>In the case where a developer may need to retain a small chunk of memory from a
pool for an indeterminate amount of time, it may be appropriate to create an
un-pooled Buffer instance using <code>SlowBuffer</code> then copy out the relevant bits.

</p>
<pre><code class="js">// need to keep around a few small chunks of memory
const store = [];

socket.on(&#39;readable&#39;, () =&gt; {
  var data = socket.read();
  // allocate for retained data
  var sb = new SlowBuffer(10);
  // copy the data into the new allocation
  data.copy(sb, 0, 0, 10);
  store.push(sb);
});</code></pre>
<p>Use of <code>SlowBuffer</code> should be used only as a last resort <em>after</em> a developer
has observed undue memory retention in their applications.

</p>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
</body>
</html>

